import requestMeeting, { request } from '@/plugins/axios'
import {
	CallChaseParamsProps,
	ChangeMicSpeakerVolumeParamsProps,
	CheckingOpenMtInfoParamsProps,
	CheckingOpenMtInfoReturnProps,
	GetCheckReturnProps,
	GetMtDetailParamsProps,
	GetMtDetailReturnProps,
	GetMtInfoExtParamsProps,
	GetMtInfoExtReturnProps,
	GetMtInfoParamsProps,
	GetMtInfoReturnProps,
	ToggleMicParamsProps,
	ToggleSpeakerParamsProps,
} from './interface'
/**
 * 获取终端信息
 * @param para 入参对象
 * @param meetingMoid 会议moid
 * @returns
 */
export const fetchGetMtInfo = async (para: GetMtInfoParamsProps, meetingMoid: string) =>
	requestMeeting<GetMtInfoReturnProps>({
		url: `/mcc/${meetingMoid}/mts/${para.mt_id}`,
		method: 'get',
		params: para,
	}).then((res) => (res.success ? res.data : undefined))
/**
 *终端检测
 * @param meetingMoid 会议moid
 * @param e164 e164号码
 * @returns
 */
export const fetchGetCheck = async (meetingMoid: string, e164: string) =>
	request<GetCheckReturnProps>({
		url: `/api/inner/ops/diagnose/conf/${meetingMoid}/mt/${e164}/real_time/`,
		method: 'get',
		params: {},
	}).then((res) => (res.success ? res.info : undefined))
/**
 *获取终端其他信息
 * @param para 入参
 * @param meetingMoid 会议moid
 * @returns
 */
export const fetchGetMtInfoExt = async (para: GetMtInfoExtParamsProps, meetingMoid: string) =>
	requestMeeting<GetMtInfoExtReturnProps>({
		url: `/mcc/${meetingMoid}/mts/${para.mt_id}/other`,
		method: 'get',
		params: para,
	}).then((res) => (res.success ? res.data : undefined))

export const fetchGetMtDetail = async (para: GetMtDetailParamsProps) =>
	requestMeeting<GetMtDetailReturnProps>({
		url: `/mcc/${para.meeting_moid}/mts/${para.mt_id}/video`,
		method: 'get',
		params: para,
	}).then((res) => (res.success ? res.data : undefined))

/**切换麦克风的 取消哑音0 设置哑音1 */
export const fetchToggleMic = async (para: ToggleMicParamsProps) =>
	requestMeeting({
		url: `/mcc/${para.meeting_moid}/mts/mute`,
		method: 'put',
		data: para,
	}).then((res) => res.success)

/**切换扬声器的 取消静音0 设置静音1 */
export const fetchToggleSpeaker = async (para: ToggleSpeakerParamsProps) =>
	requestMeeting({
		url: `/mcc/${para.meeting_moid}/mts/silence`,
		method: 'put',
		data: para,
	}).then((res) => res.success)

/**点击、滑动调节 麦克风\扬声器的音量 */
export const fetchChangeMicSpeakerVolume = async (para: ChangeMicSpeakerVolumeParamsProps) =>
	requestMeeting({
		url: `/mcc/${para.meeting_moid}/mts/${para.mt_id}/volume`,
		method: 'put',
		data: para,
	}).then((res) => res.success)

/**追呼 */
export const fetchCallChase = async (para: CallChaseParamsProps) =>
	requestMeeting({
		url: `/mcc/${para.meeting_moid}/mts/${para.mt.mt_id}/call_mode`,
		method: 'put',
		data: para,
	}).then((res) => res.success)

/**获取终端信息(根据终端e164) */
export const fetchCheckingOpenMtInfo = async (para: CheckingOpenMtInfoParamsProps) =>
	requestMeeting<CheckingOpenMtInfoReturnProps>({
		url: `/mcc/${para.meeting_moid}/mts/e164/${para.e164}`,
		method: 'get',
		params: para,
	}).then((res) => (res.success ? res.data : undefined))
